﻿Imports System.ComponentModel
 
 Public Class CTPartidaEJ


Public Structure structAncestrosPEJ 
  dim BSOId      As Long  
  Dim PSId       As Long  
End Structure


 Private _AncestrosPEJ           As structAncestrosPEJ
 Private _PartidaEJId            As Long
 Private _SecPEJ                 As Integer 
 Private _HoraIngreso            As Date
 Private _HoraEjecucion          As Date
 Private _Tasa                   As Decimal
 Private _Intermediario          As CTParamIntermediario
 Private _CantidadAsigInterm     As Decimal
 Private _Medio                  As String
 Private _Flexible               As Boolean
 Private _Observaciones          As String 
 Private _PEJConfirmada          As Boolean

 Private _PEJResumen              As String 

 Private _EstatusPEJ             As CTEstadoPEJ
 Private _LstPAJ                 As list (Of CTPartidaAjuste)

 


    Public Sub new ()
        _Flexible      = False
        _PEJConfirmada = False
        _EstatusPEJ    = New CTEstadoPEJ()  
        _LstPAJ        = New list(Of CTPartidaAjuste)              
    End Sub



Public Property AncestrosPEJ() As structAncestrosPEJ
    Get
        Return _AncestrosPEJ 
    End Get
    Set (ByVal value As structAncestrosPEJ)
        _AncestrosPEJ = value
    End Set
    
End Property
 
Public Property PartidaEJId() As long
    Get
        Return _PartidaEJId 
    End Get
    Set(ByVal value As long)
        _PartidaEJId = value
    End Set
End Property

Public Property SecPEJ() As Integer 
    Get
        Return _SecPEJ 
    End Get
    Set(ByVal value As Integer )
        _SecPEJ  = value
    End Set
End Property

Public Property HoraIngreso() As Date
    Get
        Return _HoraIngreso 
    End Get
    Set(ByVal value As date)
        _HoraIngreso = value
    End Set
End Property

Public Property HoraEjecucion() As date
    Get
        Return _HoraEjecucion 
    End Get
    Set(ByVal value As date)
        _HoraEjecucion = value
    End Set
End Property

Public Property Tasa() As decimal
    Get
        Return _Tasa 
    End Get
    Set(ByVal value As decimal)
        _Tasa = value          
        If Not _Intermediario is Nothing then 
            _PEJResumen = _Intermediario.NombreIntermediario & " --- " & _Tasa 
        Else 
            _PEJResumen = "-----  " & " --- " & _Tasa 
        End If               
    End Set
End Property

Public Property Intermediario() As CTParamIntermediario
    Get
        Return _Intermediario
    End Get
    Set(ByVal value As CTParamIntermediario)
        _Intermediario = value       
    End Set
End Property

Public Property CantidadAsigInterm() As Decimal
    Get
        Return _CantidadAsigInterm 
    End Get
    Set(ByVal value As Decimal)
        _CantidadAsigInterm = value
    End Set
End Property

Public Property Medio() As String
    Get
        Return _Medio 
    End Get
    Set(ByVal value As String)
        _Medio = value
    End Set
End Property

Public Property Flexible() As Boolean
    Get
        Return _Flexible 
    End Get
    Set(ByVal value As Boolean)
        _Flexible = value
    End Set
End Property

Public Property Observaciones() As String
    Get
        Return _Observaciones 
    End Get
    Set(ByVal value As String)
        _Observaciones = value
    End Set
End Property

Public Property PEJConfirmada() As Boolean
    Get
        Return _PEJConfirmada 
    End Get
    Set(ByVal value As Boolean)
        _PEJConfirmada = value
    End Set
End Property

Public Property EstatusPEJ() As CTEstadoPEJ
    Get
        Return _EstatusPEJ 
    End Get
    Set(ByVal value As CTEstadoPEJ)
        _EstatusPEJ = value
    End Set
End Property



Public Property LstPAJ() As  list(Of CTPartidaAjuste)
    Get
        Return _LstPAJ 
    End Get
    Set(ByVal value As  list(Of CTPartidaAjuste))
        _LstPAJ = value
    End Set
End Property




Public ReadOnly  Property PEJResumen() As String
    Get         
         If Not _Intermediario is Nothing then 
            _PEJResumen = _Intermediario.NombreIntermediario & " --- " & _Tasa 
         End If
        
        Return _PEJResumen 
    End Get
    
End Property


    Public Overrides Function ToString() As String
     

           If Not _Intermediario is Nothing then 
                         
                 _PEJResumen = _Intermediario.NombreIntermediario & " --- " & (_Tasa/100).ToString ("###.#### %")                                                           
                 Return _PEJResumen 

           Else 
              Return "------"
           End If

        
    End Function



#Region "Edición de partida"

   Public Function RegresarNuevoSubPEJ() As SubPej

      Dim subpej = new SubPej ()
      
      With subpej
      
      .PartidaEJId        = me._PartidaEJId       
      .HoraEjecucion      = me._HoraEjecucion     
      .Tasa               = me._Tasa              
      .Intermediario      = me._Intermediario.Clone() 
      .CantidadAsigInterm = me._CantidadAsigInterm
      .Medio              = me._Medio             
      .Flexible           = me._Flexible          
      .Observaciones      = me._Observaciones     

      End With

      Return subpej

   End Function


   Public sub ModificarPartida(ByRef pSubPEJ As SubPej)
      me._PartidaEJId        = pSubPEJ.PartidaEJId        
      me._HoraEjecucion      = pSubPEJ.HoraEjecucion      
      me._Tasa               = pSubPEJ.Tasa               
      me._Intermediario      = pSubPEJ.Intermediario      
      me._CantidadAsigInterm = pSubPEJ.CantidadAsigInterm 
      me._Medio              = pSubPEJ.Medio              
      me._Flexible           = pSubPEJ.Flexible           
      me._Observaciones      = pSubPEJ.Observaciones       
   End Sub

#End Region






#Region "Administración del estado de la distribución GL sobre la PEJ"

   Public Function AgregarDistribucionGL(ByRef pDistribGL As CTDistribucionGL) As Boolean
          'Se modifica tanto el estado de la PEj como de la PS
          'Invocación del T-Loader
      Return True 
   End Function

#End Region



End Class




Public Class SubPej 
   Implements  ICloneable, INotifyPropertyChanged 


 public _PartidaEJId            As Long
 public _HoraEjecucion          As Date
 public _Tasa                   As Decimal
 public _Intermediario          As CTParamIntermediario
 public _CantidadAsigInterm     As Decimal
 public _Medio                  As String
 public _Flexible               As Boolean
 public _Observaciones          As String



Public Event PropertyChanged As PropertyChangedEventHandler  Implements INotifyPropertyChanged.PropertyChanged 


Private Sub NotificarCambio (Optional ByVal propertyName As String = Nothing)
 RaiseEvent PropertyChanged(me, new PropertyChangedEventArgs(propertyName) )
End Sub


  
Public Property PartidaEJId() As long
    Get
        Return _PartidaEJId 
    End Get
    Set(ByVal value As long)
        _PartidaEJId = value
    End Set
End Property


Public Property HoraEjecucion() As date
    Get
        Return _HoraEjecucion 
    End Get
    Set(ByVal value As date)
        _HoraEjecucion = value
    End Set
End Property

Public Property Tasa() As decimal
    Get
        Return _Tasa 
    End Get
    Set(ByVal value As decimal)
        _Tasa = value
    End Set
End Property

Public Property Intermediario() As CTParamIntermediario
    Get
        Return _Intermediario
    End Get
    Set(ByVal value As CTParamIntermediario)
        _Intermediario = value
        NotificarCambio("Intermediario")
    End Set
End Property

Public Property CantidadAsigInterm() As Decimal
    Get
        Return _CantidadAsigInterm 
    End Get
    Set(ByVal value As Decimal)
        _CantidadAsigInterm = value
        NotificarCambio("CantidadAsigInterm")
    End Set
End Property

Public Property Medio() As String
    Get
        Return _Medio 
    End Get
    Set(ByVal value As String)
        _Medio = value
    End Set
End Property

Public Property Flexible() As Boolean
    Get
        Return _Flexible 
    End Get
    Set(ByVal value As Boolean)
        _Flexible = value
    End Set
End Property

Public Property Observaciones() As String
    Get
        Return _Observaciones 
    End Get
    Set(ByVal value As String)
        _Observaciones = value
    End Set
End Property



  Public Function Clone() As Object Implements System.ICloneable.Clone
        
          Dim MiClone As New SubPej()

          MiClone.PartidaEJId          = Me._PartidaEJId    
          MiClone.HoraEjecucion        = Me._HoraEjecucion
          MiClone.Tasa                 = Me._Tasa 
          MiClone.Intermediario        = Me.Intermediario  'POR REFERENCIA, NO SE CREA UNO NUEVO
          MiClone.CantidadAsigInterm   = Me._CantidadAsigInterm 
          MiClone.Medio                = Me._Medio 
          MiClone.Flexible             = Me.Flexible
          MiClone.Observaciones        = Me.Observaciones 

          Return MiClone

    End Function


End Class 



